<template>
    <div style="max-width: 1200px;text-align: center;margin: auto">
        <Form ref="formData" :model="formData" :rules="ruleValidate" :label-width="150" >
            <FormItem label="求助信息：" prop="helpTitle" style="text-align: left">
                <router-link   :to="{ name: 'donate_help_view', query: { id:formData.helpId } }">{{formData.helpTitle}}</router-link >
            </FormItem>
            <FormItem label="求助者用户名：" prop="helpUserName" style="text-align: left">
                {{formData.helpUserName}}
            </FormItem>
            <FormItem label="捐赠人用户名：" prop="donatorUserName" style="text-align: left">
                {{formData.donatorUserName}}
            </FormItem>
            <FormItem label="捐赠类型：" prop="type" style="text-align: left">
                <Select v-model="formData.type" style="width:300px">
                    <Option v-for="item in donateTypeDict" :value="item.value" :key="item.value">{{ item.name }}</Option>
                </Select>
            </FormItem>
            <FormItem label="捐赠内容说明：" prop="content">
                <Input v-model="formData.content" type="textarea" :autosize="{minRows: 3,maxRows: 6}"></Input>
            </FormItem>
            <div style="text-align: center;margin: 15px">
                <Button @click="handleReset('formData')">重置</Button>
                <Button type="primary" @click="handleSubmit('formData')" style="margin-left: 8px">保存</Button>
            </div>
            <!--加载中显示 -->
            <Spin size="large" fix v-if="spinShow"></Spin>
        </Form>
    </div>
</template>

<script>
    import Base from '@/components/table/BaseEdit.vue';
    import user from '@/common/user';
    import dictUtils from '@/common/dictUtils.js';
    export default {
        extends:Base,
        data() {
            dictUtils.getDictList("donate_type").then((res)=>{
                this.donateTypeDict=res.records;
            });
            return {
                ruleValidate: {
                    type: [
                        { required: true, message: '请输入捐赠类型!', trigger: 'change' },
                    ],
                    content: [
                        { required: true, message: '请输入捐赠内容说明!', trigger: 'blur' },
                    ],
                },
                help:{},
                donateTypeDict:[],
                formData:{}
            }
        },
        mounted(){
            this.initData();
        },
        methods: {
            loadDataById(id){
                this.load("/api/donate/read",{id})
            },handleSubmit (name) {
                //保存
                if(this.formData.auditResult == '02'){
                    this.formData.auditResult='00';
                }
                this.save(name,"/api/donate/save",()=>{
                    this.$router.push("/donate/donate/myList")
                });
            },initData(){
                let helpId=this.$route.query.helpId;
                let id=this.$route.query.id;

                // 新增
                if(helpId != null && helpId != ""){
                    this.$axiosUtils.post("/api/help/readByMap",{id:helpId}).then((res)=>{
                        this.formData={};
                        this.formData.donatorId=user.getUser().id;
                        this.formData.donatorUserName=user.getUser().userName;
                        this.formData.helpUserName=res.helpUserName;
                        this.formData.helpTitle=res.title;
                        this.formData.helpId=helpId;
                    }).catch(function (error) {
                        this.$Message.error(error);
                    })
                }else if(id != null && id != ""){
                    //修改
                    this.$axiosUtils.post("/api/donate/readByMap",{id}).then((res)=>{
                        this.formData=res;
                    }).catch(function (error) {
                        this.$Message.error(error);
                    })
                }else{
                    this.$Message.error("页面出错！");
                }
            }
        }
    }
</script>

<style scoped>

</style>
